﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NextAction.Domain.Abstract;
using NextAction.Domain.Entities;

namespace NextAction.WebUI.Models
{
    public class GtdTaskFactory
    {
        protected IGtdEnityRepository repository;

        public GtdTaskFactory(IGtdEnityRepository gtdRepository)
        {
            repository = gtdRepository;
        }

        public GtdTaskFactory()
        {
        }

        public GtdTask CreateTask(BucketType bucketType, string taskName)
        {
            return new GtdTask()
            {
                TaskType = bucketType.GetGtdTaskType(),
                Name = taskName,
                ScheduleDate = bucketType.GetScheduleDate()
            };
        }

        public GtdTaskIndexViewModel CreateIndexModel(BucketType bucketType)
        {

            return new GtdTaskIndexViewModel
            {
                GtdTasks = repository.GetGtdTasks(
                    bucketType.GetGtdTaskType(), 
                    bucketType.GetScheduleFilter()),
                BucketType = bucketType
            };
        }

        public IEnumerable<GtdTask> GetTasksForProject(int projectID)
        {
            return repository.GetTasksForProject(projectID);
        }

        public GtdTaskEditViewModel CreateEditModel(int? projectID, BucketType bucketType)
        {
            return CreateEditModel(CreateGtdTask(projectID, bucketType));
        }

        public GtdTaskEditViewModel CreateEditModel(int taskID)
        {
            return CreateEditModel(repository.GetGtdTask(taskID));
        }

        public GtdTask GetTask(int taskID)
        {
            return repository.GetGtdTask(taskID);
        }

        public GtdTaskEditViewModel CreateEditModel(GtdTask task)
        {
            return new GtdTaskEditViewModel
            {
                GtdTask = task,
                GtdProjects = repository.GetGtdProjectsWithDefault(),
                Priorities = repository.GetPriorities().ToList()
            };
        }

        private GtdTask CreateGtdTask(int? projectID, BucketType bucketType)
        {
            return new GtdTask()
            {
                TaskType = bucketType.GetGtdTaskType(),
                ProjectID = projectID ?? 0
            };
        }



    }
}